/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.packet.server;

import java.io.IOException;

import lineage.core.Opcodes;
import lineage.model.L1Character;
import lineage.packet.L1AbstractPacketServer;
import lineage.util.L1Point;

/**
 * 处理对象的移动.
 * <p>
 * 向周围可见对象发送,更新位置用
 * 
 * @version 2014年4月6日上午10:46:59
 * @author jrwz
 */
public final class S_MovePacket extends L1AbstractPacketServer {
    private byte[] _byte = null;

    /**
     * 移动.
     * 
     * @param cha
     *            - 对象
     */
    public S_MovePacket(final L1Character cha) {
        int locX = cha.getX();
        int locY = cha.getY();
        final int heading = cha.getHeading();
        locX += L1Point.HEADING_TABLE_XR[heading];
        locY += L1Point.HEADING_TABLE_YR[heading];

        writeC(Opcodes.S_OPCODE_MOVE_OBJECT);
        writeD(cha.getId());
        writeH(locX);
        writeH(locY);
        writeC(heading);
        writeC(0x80);
    }

    @Override
    public byte[] getContent() throws IOException {
        if (this._byte == null) {
            this._byte = this.getBytes();
        }
        return this._byte;
    }
}
